﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuxiWTO.Mapping;
using WutiWTO.Common;

namespace WuxiWTO.Web
{
    public partial class complainList : System.Web.UI.Page
    {
        WTODataContext ctx = new WTODataContext();
        PagedDataSource psd = new PagedDataSource();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        private void BindGrid()
        {
            var query = (from c in ctx.Complaints orderby c.update_date descending where c.display_toppage == '1' select c).AsQueryable();

            List<Complaint> list = query.ToList();
            AspNetPager1.RecordCount = list.Count; ;
            psd.DataSource = list;
            psd.AllowPaging = true;
            psd.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            psd.PageSize = AspNetPager1.PageSize;

            this.rptArticle.DataSource = psd;
            this.rptArticle.DataBind();
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid();
        }

        protected void rptArticle_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var item = e.Item.DataItem;
                Complaint cat = item as Complaint;

                Label lblProcessTime = e.Item.FindControl("lblProcessTime") as Label;
                lblProcessTime.Text = cat.update_date.GetValueOrDefault().ToShortDateString();
            }
        }
    }
}